<template>
  <tr>
    <td colspan="5">
      名称: <input type="text" v-model.trim="name" /> 价格:
      <input
        type="text"
        v-model.trim="price"
        onkeyup="this.value=this.value.replace(/\D/g,'')"
      />
    </td>
    <td>
      <button @click="add">添加</button>
    </td>
  </tr>
</template>

<script>
export default {
  data() {
    return {
      name: "",
      price: "",
    };
  },

  created() {},

  methods: {
    add() {
      if (!this.name || !this.price) return alert("请输入数据");
      this.$emit("addList", this.name, this.price);
      this.name = "";
      this.price = "";
    },
  },
};
</script>

<style scoped></style>
